﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace VietImage.Models
{
    public partial class Permission
    {
        #region Properties
        #endregion

        #region Methods
        #endregion

        #region Static Methods
        public static List<Permission> GetList()
        {
            VietImageDataClassesDataContext _db = new VietImageDataClassesDataContext();
            var v = _db.Permissions.OrderByDescending(p => p.ID);
            if (v.Count() == 0)
                return null;
            return v.ToList();
        }

        private static List<ErrorItem> InputInfomationValidation(Permission permission)
        {
            List<ErrorItem> errorList = new List<ErrorItem>();
            if (permission.Description.Length > 20)
                errorList.Add(new ErrorItem("Description", "Description is only allow up to 20 characters."));
            return errorList;
        }

        public static List<ErrorItem> Insert(ref Permission permission)
        {
            List<ErrorItem> errorList = InputInfomationValidation(permission);
            if (errorList.Count == 0)
            {
                System.Object ob = (System.Object)permission;
                if (!Provider.Insert(ref ob, "Permissions"))
                    errorList.Add(new ErrorItem("Insert", "Failed."));
            }
            return errorList;
        }

        //public static List<ErrorItem> ChangeInformation(Permission permission)
        //{
        //    List<ErrorItem> errorList = InputInfomationValidation(permission);
        //    if (errorList.Count == 0)
        //    {
        //        if (!Provider.Update())
        //            errorList.Add(new ErrorItem("Update", "Failed.");
        //    }
        //    return errorList;
        //}
        #endregion
    }
}